package com.wzl.mixed.controller;

import com.wzl.common.VkPublicResponse;
import com.wzl.mixed.config.JsCacheMgrConfig;
import com.wzl.mixed.config.JsCacheMgrConfigHolder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
 * 读取配置文件
 *
 * @author weizhongli
 * @since 1.0, 2023/05/05 14:43
 */
@Slf4j
@Controller
@RequestMapping("/read")
public class MpReadProperController {

    @Resource
    private JsCacheMgrConfigHolder jsCacheMgrConfigHolder;

    private Map<String, List<JsCacheMgrConfig>> mapConfig;

    private Map<String, List<JsCacheMgrConfig>> mapConfigBackup = new LinkedHashMap<>();


    @RequestMapping("/test1")
    public VkPublicResponse tryCatchTest1(){
        VkPublicResponse vkPublicResponse = new VkPublicResponse();
        mapConfig = jsCacheMgrConfigHolder.getMapper();
        mapConfig.forEach((sqlId, list) -> {
            List<JsCacheMgrConfig> bakList = mapConfigBackup.computeIfAbsent(sqlId, str -> new ArrayList<>());
            list.forEach(config -> bakList.add(config.copyBack()));
        });
        log.info(mapConfig.toString());
        log.info(mapConfigBackup.toString());
        vkPublicResponse.setData(mapConfig);
        return vkPublicResponse;
    }

}